using UnityEngine;
using UnityEngine.EventSystems;

namespace BasicScript.Component
{
	public class DragObject : MonoBehaviour, IPointerDownHandler, IDragHandler, IEventSystemHandler
	{
		private Vector2 Local_Pointer_Position;

		private Vector3 Panel_Local_Position;

		public RectTransform targetObject;

		private RectTransform parentRectTransform;

		private RectTransform targetRectTransform;

		private Vector2 localPointerPosition;

		private Vector3 offsetToOriginal;

		private void Awake()
		{
			if (targetObject == null)
			{
				targetObject = base.transform as RectTransform;
			}
			parentRectTransform = targetObject.parent as RectTransform;
			targetRectTransform = targetObject;
		}

		public void OnPointerDown(PointerEventData data)
		{
			Panel_Local_Position = targetRectTransform.localPosition;
			RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, data.position, data.pressEventCamera, out Local_Pointer_Position);
			targetObject.gameObject.transform.SetAsLastSibling();
		}

		public void OnDrag(PointerEventData data)
		{
			if (RectTransformUtility.ScreenPointToLocalPointInRectangle(parentRectTransform, data.position, data.pressEventCamera, out localPointerPosition))
			{
				offsetToOriginal = localPointerPosition - Local_Pointer_Position;
				targetObject.localPosition = Panel_Local_Position + offsetToOriginal;
			}
		}
	}
}
